from apps.common.base.serializers import *
from apps.pay.recordIncomesLocked.models import *


class RecordIncomesLockedBaseSerializer(BaseSerializer):
    class Meta:
        model = RecordIncomesLocked
        fields = "__all__"


class RecordIncomesLockedModelSerializer(BaseSerializer):
    userModel = serializers.SerializerMethodField()

    def get_userModel(self, obj):
        if obj.user:
            return {'id': obj.user.id, 'nickname': obj.user.nickname, 'code': obj.user.code, 'phone': obj.user.phone}
        else:
            return {}

    fromUserModel = serializers.SerializerMethodField()

    def get_fromUserModel(self, obj):
        if obj.fromUser:
            return {'id': obj.fromUser.id, 'nickname': obj.fromUser.nickname, 'code': obj.fromUser.code,
                    'phone': obj.fromUser.phone}
        else:
            return {}

    sceneLabel = serializers.SerializerMethodField()

    def get_sceneLabel(self, obj):
        if obj.scene:
            return obj.get_scene_display()
        else:
            return ''

    orderStatusLabel = serializers.SerializerMethodField()
    def get_orderStatusLabel(self, obj):
        if obj.orderStatus:
            return obj.get_orderStatus_display()
        else:
            return ''

    handleTypeLabel = serializers.SerializerMethodField()
    def get_handleTypeLabel(self, obj):
        if obj.handleType:
            return obj.get_handleType_display()
        else:
            return ''

    class Meta:
        model = RecordIncomesLocked
        fields = "__all__"
